package Collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SubListDemo {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0;i<10;i++){
            list.add(i*10);
        }
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = 0; j < list.size()-i-1; j++) {
                 /*lists.add(list.get(j));*/
                Collections.swap(list,j,j+1);
            }
        }
        System.out.println("list"+list);
        System.out.println("---------------------------------------");
        List<Integer> sublist = list.subList(3,8);
        System.out.println("sublist"+sublist);
        System.out.println("---------------------------------------");
        //将子集的每个元素都扩大10倍
        for (int i=0;i<sublist.size();i++){
            sublist.set(i,sublist.get(i)*10);
        }
        System.out.println("sublist"+sublist);
        //对子集的操作就是对原集合对应的元素操作
        System.out.println("list"+list);
        System.out.println("---------------------------------------");
        list.set(3,1000);//将原集合下标为3的元素的数据修改为1000；
        System.out.println("list"+list);
        //原集合数据改变后，子集数据跟着变了
        System.out.println("sublist"+sublist);
        System.out.println("---------------------------------------");
        list.remove(0);
        System.out.println("list"+list);
        //原集合长度修改之后，子集将不能再进行任何操作，操作则发生异常，都是可以重新获取子类
        List<Integer> sublist1 = list.subList(3,8);
        System.out.println("sublist1"+sublist1);//运行时发生不支持修改异常
        System.out.println("---------------------------------------");

     }
}
